function varargout = RiddleMan2(varargin)
% RIDDLEMAN2 MATLAB code for RiddleMan2.fig
%      RIDDLEMAN2, by itself, creates a new RIDDLEMAN2 or raises the existing
%      singleton*.
%
%      H = RIDDLEMAN2 returns the handle to a new RIDDLEMAN2 or the handle to
%      the existing singleton*.
%
%      RIDDLEMAN2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RIDDLEMAN2.M with the given input arguments.
%
%      RIDDLEMAN2('Property','Value',...) creates a new RIDDLEMAN2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before RiddleMan2_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to RiddleMan2_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help RiddleMan2

% Last Modified by GUIDE v2.5 25-Mar-2012 20:06:56

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @RiddleMan2_OpeningFcn, ...
    'gui_OutputFcn',  @RiddleMan2_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before RiddleMan2 is made visible.
function RiddleMan2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to RiddleMan2 (see VARARGIN)

% Choose default command line output for RiddleMan2
handles.output = hObject;

set( handles.RiddleMan,'Units', 'pixels' );

%get your display size
screenSize = get(0, 'ScreenSize');

%calculate the center of the display
position = get( handles.RiddleMan,'Position' );
position(1) = (screenSize(3)-position(3))/2;
position(2) = (screenSize(4)-position(4))/2;

%center the window
set( handles.RiddleMan,'Position', position );

pMan(:,:,1) =[0   0   0    0    0    0    0    0  255  255  255  255  255  255  255    0    0    0    0    0    0    0    0    0
    0   0   0    0    0    0  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0    0    0
    0   0   0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0
    0   0   0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0
    0   0   0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0
    0   0   0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0
    0   0   0    0    0    0  255  255  255  255    0    0  255  255  255  255  255  255  255  255  255  255    0    0
    0   0   0    0    0    0    0  255  255  255    0    0  255  255  255  255  255  255  255  255  255  255  255    0
    0   0   0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0
    0   0   0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0   0   0    0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0   0   0    0    0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255
    0   0   0    0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0   0   0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0   0   0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0   0   0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0
    0   0   0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0
    0   0   0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0
    0   0   0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0
    0   0   0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0
    0   0   255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0
    0   0   0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0
    0   0   0    0    0    0  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0    0    0
    0   0   0    0    0    0    0    0  255  255  255  255  255  255  255    0    0    0    0    0    0    0    0    0];

pMan(:,:,2) = pMan(:,:,1);
pMan(:,:,3) = zeros(24,24);

pMan2(:,:,1) = [0    0    0    0    0    0    0    0  255  255  255  255  255  255  255    0    0    0    0    0    0    0    0    0
    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0    0    0
    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0
    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0
    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0
    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0
    0  255  255  255  255  255  255  255  255  255    0    0  255  255  255  255  255  255  255  255  255  255    0    0
    255  255  255  255  255  255  255  255  255  255    0    0  255  255  255  255  255  255  255  255  255  255  255    0
    255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0
    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0    0    0    0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0    0    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255
    255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0
    255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0
    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0
    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0
    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0
    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0
    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0
    0    0    0    0    0    0  255  255  255  255  255  255  255  255  255  255  255    0    0    0    0    0    0    0
    0    0    0    0    0    0    0    0  255  255  255  255  255  255  255    0    0    0    0    0    0    0    0    0];

pMan2(:,:,2) = pMan2(:,:,1);
pMan2(:,:,3) = zeros(24,24);
handles.pMan = pMan;
handles.pMan2 = pMan2;

[y fs bits] = wavread('openingsong.wav');
sound(y,fs,bits);
axes(handles.logoAxes);
I=imread('pacman logo.png');
imagesc(I);
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(handles.logoAxes,'handlevisibility','off','visible','off');
axes(handles.helpAxes);
I=imread('ghosts.png');
imagesc(I);
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(handles.helpAxes,'handlevisibility','off','visible','off');
axes(handles.life1Axes);
imshow(pMan);
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(handles.life1Axes,'handlevisibility','off','visible','off');
axes(handles.life2Axes);
imshow(pMan);
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(handles.life2Axes,'handlevisibility','off','visible','off');
maze=imread('maze.png');
pos = {374:397,222:245,1:3};
maze(pos{1},pos{2},pos{3}) = pMan;
axes(handles.mazeAxes);
imagesc(maze);
% Turn the handlevisibility off so that we don't inadvertently plot into the axes again
% Also, make the axes invisible
set(handles.mazeAxes,'visible','off');
handles.pos = pos;
handles.maze = maze;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes RiddleMan2 wait for user response (see UIRESUME)
%uiwait(handles.RiddleMan);


% --- Outputs from this function are returned to the command line.
function RiddleMan2_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


% --- Executes on button press in help.
function help_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.mainMenu,'visible','off')
set(handles.helpMenu,'visible','on')
% hObject    handle to help (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in options.
function options_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.mainMenu,'visible','off')
set(handles.optionsMenu,'visible','on')
% hObject    handle to options (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in quit.
function quit_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
quit = questdlg('Are You Sure You Want To Quit?','Riddle-Man','Yes','No','No');
if strcmpi(quit,'yes')
    delete(handles.output)
end
% hObject    handle to quit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in vsCPU.
function vsCPU_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
% hObject    handle to vsCPU (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in twoPlayer.
function twoPlayer_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
% hObject    handle to twoPlayer (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in onePlayer.
function onePlayer_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
    [y fs bits] = wavread('openingsong.wav');
    sound(y,fs,bits);
end
if get(handles.ply1controls1,'value') == 1
    handle.dir = 'leftarrow';
else
    handle.dir = 'a';
end
set(handles.mainMenu,'visible','off')
set(handles.mazePanel,'visible','on')
axes(handles.splash)
set(handles.splash,'xtick',[],'ytick',[],'color','k','xlim',[0 1],'ylim',[0 1],'visible','off')
t(1)=text(.56,.575,'GET','fontname','courier','fontsize',60,'color','k','hor','center','fontweight','bold');
t(2)=text(.56,.495,'READY','fontname','courier','fontsize',60,'color','k','hor','center','fontweight','bold');
t(3)=text(.56,.445,'CLICK TO BEGIN','fontname','courier','fontsize',20,'color','k','hor','center','fontweight','bold');
map=hot(100);

for n=1:size(map,1)
    set(t(1:2),'color',map(n,:))
    drawnow
end
set(t(3),'color','r')
drawnow
% hObject    handle to onePlayer (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in backHelp.
function backHelp_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.mainMenu,'visible','on')
set(handles.helpMenu,'visible','off')
% hObject    handle to backHelp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in soundFX.
function soundFX_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
% hObject    handle to soundFX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of soundFX


% --- Executes on button press in saveOptions.
function saveOptions_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.mainMenu,'visible','on')
set(handles.optionsMenu,'visible','off')
% hObject    handle to saveOptions (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in defaultOptions.
function defaultOptions_Callback(hObject, eventdata, handles)
[y,fs,bits] = wavread('eating.short.wav');
sound(y,fs,bits);
set(handles.soundFX,'value',1);
set(handles.classic,'value',1);
set(handles.erau,'value',0);
set(handles.runway,'value',0);
set(handles.ply1controls1,'value',1);
set(handles.ply1controls2,'value',0);
set(handles.ply2controls1,'value',0);
set(handles.ply2controls2,'value',1);
% hObject    handle to defaultOptions (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on button press in ply1controls1.
function ply1controls1_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.ply1controls1,'Value',1)
set(handles.ply1controls2,'Value',0)
set(handles.ply2controls1,'Value',0)
set(handles.ply2controls2,'Value',1)
% hObject    handle to ply1controls1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ply1controls1


% --- Executes on button press in ply1controls2.
function ply1controls2_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.ply1controls2,'Value',1)
set(handles.ply1controls1,'Value',0)
set(handles.ply2controls1,'Value',1)
set(handles.ply2controls2,'Value',0)
% hObject    handle to ply1controls2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ply1controls2


% --- Executes on button press in ply2controls1.
function ply2controls1_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.ply2controls1,'Value',1)
set(handles.ply2controls2,'Value',0)
set(handles.ply1controls1,'Value',0)
set(handles.ply1controls2,'Value',1)
% hObject    handle to ply2controls1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ply2controls1


% --- Executes on button press in ply2controls2.
function ply2controls2_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
set(handles.ply2controls2,'Value',1)
set(handles.ply2controls1,'Value',0)
set(handles.ply1controls1,'Value',1)
set(handles.ply1controls2,'Value',0)
% hObject    handle to ply2controls2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ply2controls2


% --- Executes on button press in classic.
function classic_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
if get(handles.erau,'value') == 0 && get(handles.runway,'value') == 0
    set(handles.classic,'value',1)
end
% hObject    handle to classic (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of classic


% --- Executes on button press in runway.
function runway_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
if get(handles.classic,'Value') == 0 && get(handles.erau,'Value') == 0
    set(handles.runway,'value',1);
end
% hObject    handle to runway (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of runway


% --- Executes on button press in erau.
function erau_Callback(hObject, eventdata, handles)
if get(handles.soundFX,'Value') == 1
    [y,fs,bits] = wavread('eating.short.wav');
    sound(y,fs,bits);
end
if get(handles.classic,'value') == 0 && get(handles.runway,'value') == 0
    set(handles.erau,'value',1)
end
% hObject    handle to erau (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of erau

% --- Executes on key press with focus on RiddleMan2 or any of its controls.
function RiddleMan_WindowKeyPressFcn(hObject, eventdata, handles)
pMan = handles.pMan;
pMan2 = handles.pMan2;
maze = handles.maze;
handles.dir = eventdata.Key;

if get(handles.ply1controls1,'value') == 1
    left = 'leftarrow';
    right = 'rightarrow';
    up = 'uparrow';
    down = 'downarrow';
else
    left = 'a';
    right = 'd';
    up = 'w';
    down = 's';
end
while strcmpi(handles.dir,left)==1
    for x = 1:24
        if maze(handles.pos{1}(x),handles.pos{2}(1)-4,3) == 255
            stop = 1;
            handles.dir = 0
            break
        else
            stop = 0;
        end
    end
    if stop == 1;
        break
    end
    bound = 0;
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{2} = handles.pos{2} - 2;
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = pMan2(:,:,:);
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    pause(.2)
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{2} = handles.pos{2} - 2;
    guidata(hObject, handles);
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = pMan(:,:,:);
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    dir = get(gcf,'CurrentKey');
    if strcmpi(dir,right)
        handles.dir = dir;
    elseif strcmpi(dir,up)
        for x = 1:24
            if maze(handles.pos{1}(1)-4,handles.pos{2}(x),3) == 255
                bound = 1;
                break
            else
                bound = 0;
            end
        end
    elseif strcmpi(dir,down)
        for x = 1:24
            if maze(handles.pos{1}(24)+4,handles.pos{2}(x),3) == 255
                bound = 1;
                break
            else
                bound = 0;
            end
        end
    end
    if bound == 0
        handles.dir = dir;
    end
    handles.maze = maze;
    guidata(hObject, handles);
end
while strcmpi(handles.dir,right)
    for x = 1:24
        if maze(handles.pos{1}(x),handles.pos{2}(24)+4,3) == 255
            stop = 1;
            handles.dir = 0;
            break
        else
            stop = 0;
        end
    end
    if stop == 1;
        break
    end
    bound = 0;
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{2} = handles.pos{2} + 2;
    for x = 1:3
        maze(handles.pos{1},handles.pos{2},x) = fliplr(pMan2(:,:,x));
    end
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    pause(.1)
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{2} = handles.pos{2} + 2;
    guidata(hObject, handles);
    for x = 1:3
        maze(handles.pos{1},handles.pos{2},x) = fliplr(pMan(:,:,x));
    end
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    dir = get(gcf,'CurrentKey');
    if strcmpi(dir,left)
        handles.dir = dir;
    elseif strcmpi(dir,up)
        for x = 1:24
            if maze(handles.pos{1}(1)-4,handles.pos{2}(x),3) == 255
                bound = 1;
                break
            else
                bound = 0;
            end
        end
    elseif strcmpi(dir,down)
        for x = 1:24
            if maze(handles.pos{1}(24)+4,handles.pos{2}(x),3) == 255
                bound = 1;
                break
                else
                bound = 0;
            end
        end
    end
    if bound == 0
        handles.dir = dir;
    end
    handles.maze = maze;
    guidata(hObject, handles);
end
while strcmpi(handles.dir,up)
    for x = 1:24
        if maze(handles.pos{1}(1)-4,handles.pos{2}(x),3) == 255
            stop = 1;
            handles.dir = 0;
            break
        else
            stop = 0;
        end
    end
    if stop == 1;
        break
    end
    bound = 0;
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{1} = handles.pos{1} - 2;
    for x = 1:3
        maze(handles.pos{1},handles.pos{2},x) = rot90(pMan2(:,:,x),3);
    end
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    pause(.1)
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{1} = handles.pos{1} - 2;
    guidata(hObject, handles);
    for x = 1:3
        maze(handles.pos{1},handles.pos{2},x) = rot90(pMan(:,:,x),3);
    end
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    dir = get(gcf,'CurrentKey');
    if strcmpi(dir,down)
        handles.dir = dir;
    elseif strcmpi(dir,left)
        for x = 1:24
            if maze(handles.pos{1}(x),handles.pos{2}(1)-4,3) == 255
                bound = 1;
                break
            else
                bound = 0;
            end
        end
    elseif strcmpi(dir,right)
        for x = 1:24
            if maze(handles.pos{1}(x),handles.pos{2}(1)+4,3) == 255
                bound = 1;
                break
                else
                bound = 0;
            end
        end
    end
    if bound == 0
        handles.dir = dir;
    end
    handles.maze = maze;
    guidata(hObject, handles);
end
while strcmpi(handles.dir,down)
    for x = 1:24
        if maze(handles.pos{1}(24)+4,handles.pos{2}(x),3) == 255
            stop = 1;
            handles.dir = 0;
            break
        else
            stop = 0;
        end
    end
    if stop == 1;
        break
    end
    bound = 0;
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{1} = handles.pos{1} + 2;
    for x = 1:3
        maze(handles.pos{1},handles.pos{2},x) = rot90(pMan2(:,:,x));
    end
    axes(handles.mazeAxes);
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    pause(.1)
    maze(handles.pos{1},handles.pos{2},handles.pos{3}) = zeros(24,24,3);
    handles.pos{1} = handles.pos{1} + 2;
    guidata(hObject, handles);
    for x = 1:3
        maze(handles.pos{1},handles.pos{2},x) = rot90(pMan(:,:,x));
    end
    axes(handles.mazeAxes);
    imagesc(maze);
    set(handles.mazeAxes,'visible','off');
    dir = get(gcf,'CurrentKey');
    if strcmpi(dir,up)
        handles.dir = dir;
    elseif strcmpi(dir,left)
        for x = 1:24
            if maze(handles.pos{1}(x),handles.pos{2}(1)-4,3) == 255
                bound = 1;
                break
            else
                bound = 0;
            end
        end
    elseif strcmpi(dir,right)
        for x = 1:24
            if maze(handles.pos{1}(x),handles.pos{2}(1)+4,3) == 255
                bound = 1;
                break
                else
                bound = 0;
            end
        end
    end
    if bound == 0
        handles.dir = dir;
    end
    handles.maze = maze;
    guidata(hObject, handles);
end
pause(.1)
% hObject    handle to RiddleMan2 (see GCBO)
% eventdata  structure with the following fields (see FIGURE)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function RiddleMan_WindowButtonDownFcn(hObject, eventdata, handles)
delete(handles.splash)
% hObject    handle to RiddleMan (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes when user attempts to close RiddleMan.
function RiddleMan_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to RiddleMan (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
quit = questdlg('Are You Sure You Want To Quit?','Riddle-Man','Yes','No','No');
if strcmpi(quit,'yes')
    delete(handles.output)
end
